/**
 * 
 */
package com.program.spring.test.control;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @package com.program.spring.bingo.module.home.control
 * @File    homeControl.java
 * @Author：苏赞 
 * @CreateTime：2011-11-17下午05:21:10
 */

@Controller
//@RequestMapping(value = "/a")
public class BingoHomeControl {

	//	@Resource(name = "BingoHomeService")
	//	private BingoHomeService m_oBingoHomeService;
	//	
	//	@Resource(name = "test")
	//	private Itest oTest;
	//	
	//	@RequestMapping(value = "/subsys/bingo/module/home/index.do",method = RequestMethod.GET)
	//	public String test(HttpServletRequest _oRequest,HttpServletResponse _oResponse,ModelMap oModelMap ){
	//		
	//		List<Ad> aList=(List<Ad>) m_oBingoHomeService.test();
	//		
	//		_oRequest.setAttribute("Adlist", aList);
	//		oTest.ff();
	//		
	//		
	//		return "/test/module/home/index.jsp";
	//	}
	//	
	//	@RequestMapping(value = "/subsys/bingo/module/home/save.do",method = RequestMethod.GET)
	//	public String savePreson(@ModelAttribute("personToEditOrCreate")preson oP){
	//	
	//		System.out.println(oP.getFirstName());
	//		
	//		return "redirect:/test/module/home/index.jsp"; 
	//	}
	//	
	//	@RequestMapping(value = "/subsys/bingo/module/home/ajax.do" , method = RequestMethod.GET)
	//	@ResponseBody
	//	public Map<String, Object> getBingoProcedures(HttpServletRequest _oRequest){
	//		
	//		
	//		String sWho = _oRequest.getParameter("who");
	//		
	//		 Map<String, Object> oMap = new HashMap<String, Object>();
	//
	//		 String sMessage = sWho + "说带丁华我们去东莞";
	//		 
	//		 if(sMessage != null){
	//		 
	//			 oMap.put("success", true);
	//			 oMap.put("msg", sMessage);
	//			 
	//		 }else{
	//			 oMap.put("success", false);
	//			 oMap.put("msg", "错误");
	//		 }
	//		 
	//		 
	//		return oMap;
	//		
	//	}
	//	
	@RequestMapping(value = "/subsys/iptest.do", method = RequestMethod.GET)
	public String test(HttpServletRequest _oRequest) {

		System.out.println("测试IP:");

		String ip = _oRequest.getRemoteAddr();
		//System.out.println(_oRequest.getHeader("HTTP_X_FORWARDED_FOR"));
		System.out.println(ip);

		System.out.println(getIp(_oRequest));

		return "/test/module/home/index.jsp";
	}

	public static String getIp(HttpServletRequest request) {
		String ip = request.getHeader("X-Real-IP");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
			ip = request.getHeader("X-Forwarded-For");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
			ip = request.getHeader("Proxy-Client-IP");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
			ip = request.getHeader("WL-Proxy-Client-IP");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
			ip = request.getRemoteAddr();
		if (ip != null && ip.trim().length() > 0) {
			if (ip.indexOf(",") > 0) {
				String ips[] = ip.split(",");
				return ips[ips.length - 1];
			}
			return ip;

		}
		return "0.0.0.0";
	}

}
